/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.eduardcapell.lopodder.io.mp3;

import com.eduardcapell.lopodder.gui.PlayerGUI;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.JSlider;
import javazoom.jlgui.basicplayer.BasicController;
import javazoom.jlgui.basicplayer.BasicPlayerEvent;
import javazoom.jlgui.basicplayer.BasicPlayerListener;

/**
 *
 * @author edu
 */
public class PlayerListener implements BasicPlayerListener {
    
    private PlayerGUI gui = null;
    private long duration = 0;
    

    public PlayerListener(PlayerGUI gui) {
        this.gui = gui;
    }
    
    public void opened(Object stream, Map properties) {
        duration = Long.parseLong(properties.get("duration").toString());
    }

    /*
     * mp3.position.microseconds
     * mp3.equalizer
     * mp3.frame.size.bytes
     * mp3.frame
     * mp3.frame.bitrate
     * mp3.position.byte
     */
    public void progress(int bytesread, long microseconds,
        byte[] pcmdata, Map properties) {

        double d = (double) microseconds / (double) duration * 100d;
        gui.updateSlider((int) d);
        gui.updateTimer(microseconds);
    }

    public void stateUpdated(BasicPlayerEvent evt) {
        if (evt.getCode() == BasicPlayerEvent.PAUSED) {
            System.out.println("Paused at " + evt.getValue());
        } else if (evt.getCode() == BasicPlayerEvent.RESUMED) {
            System.out.println("Resumed at " + evt.getValue());
        }
    }

    public void setController(BasicController arg0) {
        System.out.println("setController");
    }

}
